// ignore_for_file: prefer_const_constructors_in_immutables, use_key_in_widget_constructors, prefer_const_constructors, sized_box_for_whitespace
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_navigation/get_navigation.dart';

import 'color_utils.dart';
import 'common_utils.dart';

//横线
class HorizontalLine extends StatelessWidget {
  final double width;
  final double height;
  final Color color;
  final double horizontal;

  HorizontalLine({
    this.width = 25,
    this.height = 0.5,
    this.color = const Color(0xFFF4F5F7),
    this.horizontal = 0.0,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      height: height,
      width: width,
      color: color,
      margin: EdgeInsets.symmetric(horizontal: horizontal),
    );
  }
}

//竖线
class VerticalLine extends StatelessWidget {
  final double width;
  final double height;
  final Color color;
  final double vertical;

  VerticalLine({
    this.width = 1.0,
    this.height = 25,
    this.color = const Color.fromRGBO(209, 209, 209, 0.5),
    this.vertical = 0.0,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: width,
      color: Color(0xffDCE0E5),
      margin: EdgeInsets.symmetric(vertical: vertical),
      height: height,
    );
  }
}

//间隔
class Space extends StatelessWidget {
  final double width;
  final double height;

  Space({this.width = 1.0, this.height = 1.0});

  @override
  Widget build(BuildContext context) {
    return Container(width: width, height: height);
  }
}

//AppBar
AppBar xdAppBar(String title,
    {String? leftImageUrl,
    Widget? titleView,
    Color titleColor = ThemeColors.clff000000,
    bool isBack = true,
    Color? backColor,
    Color bgColor = ThemeColors.clfff5f6f7,
    backAction,
    List<Widget>? rightWidgets}) {
  leftImageUrl ??= 'assets/images/common/nav_left_arrow.png';
  return AppBar(
      backgroundColor: bgColor,
      centerTitle: true,
      leadingWidth: 52,
      shadowColor: Colors.transparent,
      systemOverlayStyle: SystemUiOverlayStyle.dark,   //设置状态栏文字黑色
      title: titleView ??
          Text(
            title,
            style: TextStyle(
                fontSize: 16, color: titleColor, fontWeight: FontWeight.w500),
          ),
      leading: isBack
          ? IconButton(
              iconSize: 50,
              icon: Image.asset(leftImageUrl,
                  height: 32, width: 32, color: backColor),
              onPressed: () {
                if (backAction != null) {
                  backAction();
                } else {
                  CommonUtil.closeKeyBoard();
                  Get.back();
                }
              },
            )
          : null,
      actions: rightWidgets);
}
